IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('InlineMax','FN'))
    DROP function InlineMax
GO
create function InlineMax(@val1 int, @val2 int)
returns int
as
begin
  if @val1 > @val2
    return @val1
  return isnull(@val2,@val1)
end